/*
 * Copyright 2017 JessYan
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.cj.mobile.iabp.mvp.ui.holder;

import android.view.View;
import android.widget.ImageView;

import androidx.annotation.NonNull;
import androidx.cardview.widget.CardView;

import com.bumptech.glide.Glide;
import com.cj.mobile.iabp.R;
import com.cj.mobile.iabp.app.utils.EventBusTags;
import com.cj.mobile.iabp.mvp.model.entity.MainEvent;
import com.jess.arms.base.BaseHolder;
import com.jess.arms.integration.EventBusManager;

import butterknife.BindView;

/**
 * ================================================
 * <p>
 * ================================================
 */
public class CameraContentItemHolder extends BaseHolder<String> implements View.OnClickListener {
    @BindView(R.id.item_camera_a_layout)
    CardView mCardView;
    @BindView(R.id.btn_itemcontentlayout_close)
    ImageView mClose;
    @BindView(R.id.imvi_itemcontentlayout_camera)
    ImageView mImage;

    // 类型
    private int type = 0;
    // 是否使用默认背景(默认是灰色，非默认是白色)
    private boolean isDefaultBg;

    public CameraContentItemHolder(View itemView) {
        super(itemView);

    }

    public void initData(int type, boolean isDefaultBg) {
        this.type = type;
        this.isDefaultBg = isDefaultBg;
    }

    @Override
    public void setData(@NonNull String info, int position) {
        // 设置图片
        Glide.with(mClose.getContext()).load(info).into(mImage);

//        if (!isDefaultBg) {
//            mCardView.setCardBackgroundColor(R.drawable.dialog_white_bg);
//        }

        mClose.setOnClickListener(this);
        mImage.setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        if (v.getId() == R.id.btn_itemcontentlayout_close) {
            EventBusManager.getInstance().post(new MainEvent(EventBusTags.DELETE_IMAGE_TAG, getPosition(), type), EventBusTags.HOME_TAG);
        }
    }

    @Override
    protected void onRelease() {
        this.mClose = null;
        this.mImage = null;
    }
}
